package com.fucking.great.context.util;

import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.ClassUtil;
import cn.hutool.core.util.ReflectUtil;
import cn.hutool.log.Log;
import cn.hutool.log.LogFactory;

import java.lang.reflect.Method;

public abstract class DebugUtil {
    public static final Log log = LogFactory.get();

    /**
     * 打印对象所有的get方法,用于写代码，不想看api文档的利器
     * @param obj
     */
    public static void printAllGetMethode(Object obj,String... filterName){
        Method[] gets = ReflectUtil.getMethods(ClassUtil.getClass(obj), (filter) -> {
            String name = filter.getName();
            if (name.startsWith("get") && !ArrayUtil.contains(filterName,name) && filter.getParameterCount() == 0) {
                return true;
            } else {
                return false;
            }
        });
        log.debug("类为[{}]的对象[{}]的get方法执行结果", ClassUtil.getClassName(obj,false), obj);
        for (Method get : gets) {
            try {
                log.debug("方法名为[{}],内容为[{}]",get.getName() , ReflectUtil.invoke(obj,get) );
            } catch (Throwable e) {
                e.printStackTrace();
            }
        }
    }
}
